import { operateMgr } from "./operateMgr.js"
import { SportData} from '../datas/SportData.js';
import { protocol } from '../protocol.js';

export const operateSteps = {
    readStep(_callback)
    {
        //设置回调
        operateMgr.setCallback(protocol.SPORT_CURRENT_READ,this.onStepResult);
        this.callback = _callback;

        const hexNumbers1 = [operateMgr.protocolHex(protocol.SPORT_CURRENT_READ), '0x00']
        const uint8Array1 = new Uint8Array(hexNumbers1.map(hex => parseInt(hex, 16)));
        operateMgr.writeValue(uint8Array1);
    },

    onStepResult:(cmd,dataView,hexArray)=>
    {
        const data = new SportData();
        if(dataView.byteLength<20)
        {
            console.log("读取步数长度低于20",dataView.byteLength);
        }
        else
        {
            console.log("读取步数",cmd,"步数：",dataView.getUint16(3));
            data.step = dataView.getUint16(3);
            // data.dis = dataView.getUint16(3);
            // data.kcal = dataView.getUint16(3);
            // data.kcal = dataView.getUint16(3);
            data.calcType = 2;
        }  
       operateSteps.callback(data);
    },

        /**输入的字符串解析为十六进制整数*/
    str_hex_dec(var_str) {
        if (var_str === "FFFFFFFF") {
            var_str = "0";
        }
    
        return parseInt(var_str, 16);
    },
    /**16进制数组 然后转 字符串数组 */
    HexToStrArr(hexArray)
    {

    }
}